package com.example.lenovo.weiyi;

import android.os.Bundle;
import android.webkit.WebView;

import com.com.ruanmeng.demon.AboutUsM;
import com.com.ruanmeng.utils.PreferencesUtils;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.rest.Request;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;
import nohttp.CallServer;
import nohttp.CustomHttpListener;
import share.Const;
import share.HttpIP;

public class AboutusActivity extends BaseActivity {

    @BindView(R.id.web_aboutus)
    WebView webAboutus;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_aboutus);
        ButterKnife.bind(this);
        ChangLayTitle("关于我们");
        LayBack();
        getData();
    }

    public void getData() {
        Request<String> mRequest = NoHttp.createStringRequest(HttpIP.AboutUs, Const.POST);
        mRequest.addHeader("token", PreferencesUtils.getString(AboutusActivity.this, "uid"));
        // 添加到请求队列
        CallServer.getRequestInstance().add(AboutusActivity.this, 0, mRequest,
                new CustomHttpListener(AboutusActivity.this, true, AboutUsM.class) {
                    @Override
                    public void doWork(Object data, boolean isOne) {
                        AboutUsM model = ((AboutUsM) data);
                        String str_canshu = "<!doctype html><html>\n<meta charset=\"utf-8\"><style type=\"text/css\">body{padding:0; margin:0;}\n." +
                                "view_h1{ width:90%%;display:block; "
                                + "overflow:hidden; margin:0 auto; font-size:1.2em; color:#333; padding:1em 0;"
                                + " line-height:1.2em; text-align:center;}\n.view_time{ width:90%; display:block; "
                                + "text-align:center;overflow:hidden; margin:0 auto; font-size:1em; color:#999;}\n.con{width:90%; "
                                + "margin:0 auto; color:#fff; color:#333; padding:0.5em 0; overflow:hidden; display:block; font-size:0.92em;"
                                + " line-height:1.8em;}\n.con h1,h2,h3,h4,h5,h6{ font-size:1em;}\n .con img{width: auto; max-width: 100%;"
                                + "height: auto;margin:0 auto;}\n</style>\n<body style=\"padding:0; margin:0; \"><div class=\"con\">"
                                +model.getObject().getContent()+ "</div></body></html>";
                        webAboutus.getSettings().setJavaScriptEnabled(true); //设置支持Javascript
                        webAboutus.loadDataWithBaseURL(HttpIP.Base_IpIMage
                                , str_canshu, "text/html", "UTF-8", null);
                    }

                    @Override
                    public void onFinally(JSONObject obj) throws JSONException {
                        super.onFinally(obj);
                    }
                }, true, true);
    }
}
